package offer.nowcoder.queue_stack;

import java.util.Stack;

/**
 * @author DengYuan2
 * @create 2021-02-15 20:59
 */
public class n_9 {
    public static void main(String[] args) {
        n_9 n = new n_9();
        n.push(1);
        n.push(2);
        n.push(3);
        try {
            System.out.println(n.pop());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    Stack<Integer> stack1 = new Stack<Integer>();
    Stack<Integer> stack2 = new Stack<Integer>();

    public void push(int node) {
        stack1.push(node);
    }

    public int pop()  {
        if (stack1.isEmpty() && stack2.isEmpty()) {
            try {
                throw new Exception("没有值");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (!stack2.isEmpty()) {
            return stack2.pop();
        }
        while (!stack1.isEmpty()) {
            stack2.push(stack1.pop());
        }
        return stack2.pop();
    }
}
